<?php
/**
 * 订单分拣日志表
 * String id
 * String order_id【订单号】
 * String site
 * String o_info【原订单信息】
 * String n_info【修改后的订单信息】
 * String add_time【修改时间】
 * String add_user【修改人】
 */
class App_Model_OrderModifyLog extends App_Model_Abstract
{
	public function init()
	{
		parent::init();
		$this->table = App_Db_Table::factory('OrderModifyLog');
	}
	
	public function add($row)
	{
		return $this->table->insert($row);
	}

	public function delete($id)
	{
		$db = $this->table->getAdapter();
		$where = $db->quoteInto('id = ?', $id);
	
		return $this->table->delete($where);
	}
	
	public function update($row, $id)
	{
		$db = $this->table->getAdapter();
		$where = $db->quoteInto('id = ?', $id);
	
		return $this->table->update($row, $where);
	}
	
	public function listAll($orderid,$site,$starttime,$endtime,$page=1,$limit=20)
	{
		$select = $this->table->select();
		if(!empty($orderid)){
			$select->where('order_id = ?',$orderid);
		}
		if(!empty($site)){
			$select->where('site = ?',$site);
		}
		if(!empty($starttime)){
			$select->where('add_time > ?',$starttime);
		}
		if(!empty($endtime)){
			$select->where('add_time < ?',$endtime);
		}
		$offset = ($page - 1) * $limit;
		$select->limit($limit,$offset);
	
		$select->order('add_time desc');
		return $this->table->fetchAll($select);
	}
	
	public function getTotalNum($orderid,$site,$starttime,$endtime)
	{
		$where="where 1 ";
	
		if(!empty($orderid)){
			$where.=" and order_id='$orderid'";
		}
		if(!empty($site)){
			$where.=" and site='$site'";
		}
		if(!empty($starttime)){
			$where.=" and add_time>='".$starttime."'";
		}
		if(!empty($endtime)){
			$where.=" and add_time<='".$endtime."'";
		}
		return $this->table->getAdapter()->fetchOne("select count(*) from order_modify_log ".$where);
	}
	
}